package com.gonsin.gview.model.dynamic.table;

import com.gonsin.gview.annotations.board.form.GFormItem;
import com.gonsin.gview.annotations.enums.ColumnType;
import com.gonsin.gview.annotations.filter.ColumnFilter;
import com.gonsin.gview.annotations.filter.NoFilter;
import com.gonsin.gview.model.GFormItemModel;
import com.gonsin.gview.model.dynamic.DynamicButton;
import com.gonsin.gview.model.dynamic.form.DynamicFormItem;
import com.gonsin.gview.model.struct.EnumItem;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * 动态列
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DynamicColumn {

    /**
     * 一列标题显示的名字
     */
    private String name;


    /**
     * 一列中显示对应的字段
     */
    private String keyName;


    /**
     * 和keyName作用相同，keyName是直接显示对应的字段，value是动态显示字段值
     * 使用mustache注入，如果value为""时，显示keyName对应的值，如果value非空时显示value的内容
     * 用法例如：
     * {{item.createTime}}
     * /files/{{filename}}
     */
    private String value = "";

    /**
     * 日期显示格式
     */
    private String format = "yyyy年MM月dd日 HH:mm";

    /**
     * 内置枚举名字，根据枚举名字获取枚举内容
     * 内置的枚举名字需要通过  {@code  GViewGlobalEnumsService}.addEnums
     */
    private String enumName;

    /**
     * 枚举列表
     */
    private List<EnumItem> enums = new ArrayList<>();


    /**
     * 显示的按钮
     */
    private List<DynamicButton> buttons = new ArrayList<>();

    /**
     * 列的类型
     */
    private ColumnType columnType = ColumnType.TEXT;


    /**
     * 宽度占比
     */
    private int weight = 1;

    /**
     * 图片大小
     */
    private String imageSize = "100x100";

    /**
     * 列表里塞入控件
     */
    private List<DynamicFormItem> formItems = new ArrayList<>();

    public static DynamicColumnBuilder builder(){
        return new DynamicColumnBuilder();
    }


    public static final class DynamicColumnBuilder {
        /**
         * 一列标题显示的名字
         */
        private String name;


        /**
         * 一列中显示对应的字段
         */
        private String keyName;


        /**
         * 和keyName作用相同，keyName是直接显示对应的字段，value是动态显示字段值
         * 使用mustache注入，如果value为""时，显示keyName对应的值，如果value非空时显示value的内容
         * 用法例如：
         * {{item.createTime}}
         * /files/{{filename}}
         */
        private String value = "";

        /**
         * 日期显示格式
         */
        private String format = "yyyy年MM月dd日 HH:mm";

        /**
         * 内置枚举名字，根据枚举名字获取枚举内容
         * 内置的枚举名字需要通过  {@code  GViewGlobalEnumsService}.addEnums
         */
        private String enumName;

        /**
         * 枚举列表
         */
        private List<EnumItem> enums = new ArrayList<>();


        /**
         * 显示的按钮
         */
        private List<DynamicButton> buttons = new ArrayList<>();

        /**
         * 列的类型
         */
        private ColumnType columnType = ColumnType.TEXT;


        /**
         * 宽度占比
         */
        private int weight = 1;

        /**
         * 图片大小
         */
        private String imageSize = "100x100";

        /**
         * 列表里塞入控件
         */
        private List<DynamicFormItem> formItems = new ArrayList<>();

        private DynamicColumnBuilder() {
        }

        public static DynamicColumnBuilder aDynamicColumn() {
            return new DynamicColumnBuilder();
        }

        public DynamicColumnBuilder name(String name) {
            this.name = name;
            return this;
        }

        public DynamicColumnBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicColumnBuilder value(String value) {
            this.value = value;
            return this;
        }

        public DynamicColumnBuilder format(String format) {
            this.format = format;
            return this;
        }

        public DynamicColumnBuilder enumName(String enumName) {
            this.enumName = enumName;
            return this;
        }

        public DynamicColumnBuilder enums(List<EnumItem> enums) {
            this.enums = enums;
            return this;
        }

        public DynamicColumnBuilder buttons(List<DynamicButton> buttons) {
            this.buttons = buttons;
            return this;
        }

        public DynamicColumnBuilder columnType(ColumnType columnType) {
            this.columnType = columnType;
            return this;
        }

        public DynamicColumnBuilder weight(int weight) {
            this.weight = weight;
            return this;
        }

        public DynamicColumnBuilder imageSize(String imageSize) {
            this.imageSize = imageSize;
            return this;
        }

        public DynamicColumnBuilder formItems(List<DynamicFormItem> formItems) {
            this.formItems = formItems;
            return this;
        }

        public DynamicColumn build() {
            DynamicColumn dynamicColumn = new DynamicColumn();
            dynamicColumn.setName(name);
            dynamicColumn.setKeyName(keyName);
            dynamicColumn.setValue(value);
            dynamicColumn.setFormat(format);
            dynamicColumn.setEnumName(enumName);
            dynamicColumn.setEnums(enums);
            dynamicColumn.setButtons(buttons);
            dynamicColumn.setColumnType(columnType);
            dynamicColumn.setWeight(weight);
            dynamicColumn.setImageSize(imageSize);
            dynamicColumn.setFormItems(formItems);
            return dynamicColumn;
        }
    }
}
